package com.tianqu.tms.www.attn.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Attn;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.entity.User;
import com.tianqu.tms.www.attn.viewhelper.AttnViewhelper;
import com.tianqu.tms.www.member.viewhelper.MemberInputViewHelper;

/**
 * @author zhangxueliang
 * 密码修改结果controller
 */
public class AttnLoginResultController extends TmsController{
	private Logger logger = Logger
	.getLogger(AttnLoginResultController.class);
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			AttnViewhelper view = (AttnViewhelper) uc
			.getAttribute(TmsConstants.VIEWHELP);

//			// 通过memberId查询出userId
//			Attn attn = Attn.getInstance();
//			attn = member.findMemberInfoByMemId(view.getMemberId());
		
			String userId = view.getUserId();
		
			User user = new User();
		
			user = user.getUserProfileByLoginid(userId, view.getPassword());
			user.savePwdInfo(String.valueOf(user.getId()), view.getPassword());
			
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
	}

}
